package com.neusoft.controller;

import com.neusoft.service.ClockService;
import com.neusoft.util.UserThreadUtil;
import com.neusoft.vo.AgreeAttendanceVO;
import com.neusoft.vo.ApproveAttendanceVO;
import com.neusoft.vo.Clock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;

@CrossOrigin
@RestController
public class AttendanceHandler {
	@Autowired
	private ClockService s;

//	页面载入时显示当前打卡情况
	@PostMapping("searchClock")
	Clock searchClock(@RequestBody Clock clock) {
		clock.setEmpno(Integer.parseInt(String.valueOf(UserThreadUtil.getEmpId())));
		System.out.println(clock);
		return s.searchClock(clock);
	}

	// 上班打卡
	@PostMapping("/clockin")
	public int clockIn(@RequestBody Clock clock) {
		clock.setEmpno(Integer.parseInt(String.valueOf(UserThreadUtil.getEmpId())));
		System.out.println(clock);
		return s.clockIn(clock);
	}

	// 下班打卡，结算当前用户当日考勤情况
	@PostMapping("/clockout")
	public int clockOut(@RequestBody Clock clock) {
		clock.setEmpno(Integer.parseInt(String.valueOf(UserThreadUtil.getEmpId())));
		return s.clockOut(clock);
	}

	// 页面载入时 自动查询当前员工所需补签的所有数据
	@GetMapping("/selectReattendace")
	List<Clock> selectReattendace() {
		return s.selectReattendace(Integer.parseInt(String.valueOf(UserThreadUtil.getEmpId())));
	}

	// 单击补签按钮后 将信息存入reattendace表
	@PostMapping("/reattendaceCount")
	public int reattendaceCount(@RequestBody Clock clock) {
		clock.setEmpno(Integer.parseInt(String.valueOf(UserThreadUtil.getEmpId())));
		return s.reattendaceCount(clock);
	}

	// 为审批者显示所有待审核补签信息
	@PostMapping("/selectCount")
	int selectCount(@RequestBody ApproveAttendanceVO vo) {
		return s.selectCount(vo);
	}

	// 为审批者显示所有待审核补签信息
	@PostMapping("/selectAllEmpReattendance")
	List<Clock> selectAllEmpReattendance(@RequestBody ApproveAttendanceVO vo) {
		System.out.println(vo);
		return s.selectAllEmpReattendance(vo);
	}

	// 单击“同意”/“批量同意”按钮时，将得到的集合遍历，将restate置为1，state置为8
	@PostMapping("/agreeAttendance")
	public int agree(@RequestBody AgreeAttendanceVO vo) {
		System.out.println(vo.getIds());
		return s.agree(vo.getIds());
	}

	// 单击“拒绝”/“批量拒绝”按钮时，将得到的集合遍历，将restate置为0
	@PostMapping("/refuseAttendance")
	public int refuse(@RequestBody AgreeAttendanceVO vo) {
		return s.refuse(vo.getIds());
	}

//	仅用于测试定时任务 无客户端使用此接口
	@GetMapping("/aaa")
	public int aaa() {
		return s.insertNextDay4Emps();
	}
}
